package com.zpself.module.算法练习.二叉树;

/**
 * @author By ZengPeng
 * @Description
 * @date in  2021/2/6 16:35
 * @Modified By
 */
public class 力扣_530_二叉搜索树的最小绝对差 {
    public static void main(String[] args) {
        TreeNode root = TreeNode.initRoot();
        System.out.println(getMinimumDifference(root));
    }

    private static  Integer pro=null ,min=Integer.MAX_VALUE;//上一个值
    public static  int getMinimumDifference(TreeNode root) {
        if(root.left!=null)
            getMinimumDifference(root.left);
        if(pro==null)
            pro=root.val;
        else{
            min = min<Math.abs(pro-root.val)? min :Math.abs(pro-root.val);
            pro=root.val;
        }
        if(root.right!=null)
            getMinimumDifference(root.right);
        return min;
    }
}
